<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: Chorb::Chord</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../chord_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="chord.rb">chord.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-create">#create</a></li>
					
					<li><a href="#method-i-finish">#finish</a></li>
					
					<li><a href="#method-i-join">#join</a></li>
					
					<li><a href="#method-i-lookup">#lookup</a></li>
					
					<li><a href="#method-i-print_nodes">#print_nodes</a></li>
					
					<li><a href="#method-i-succ_updated">#succ_updated</a></li>
					
					<li><a href="#method-i-succs_added">#succs_added</a></li>
					
					<li><a href="#method-i-succs_leaved">#succs_leaved</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../Chorb.html">Chorb</a></li>
				
					<li><a href="../Chorb/Chord.html">Chorb::Chord</a></li>
				
					<li><a href="../AbstractVirtualNode.html">AbstractVirtualNode</a></li>
				
					<li><a href="../Key.html">Key</a></li>
				
					<li><a href="../ListenerVirtualNode.html">ListenerVirtualNode</a></li>
				
					<li><a href="../LocalVirtualNode.html">LocalVirtualNode</a></li>
				
					<li><a href="../RemoteVirtualNode.html">RemoteVirtualNode</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">Chorb::Chord</h1>

		<div id="description">
			<p>
Classe principal. Representa o <a href="Chord.html">Chord</a> com todos os
seus Vnodes.  
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(num_vnodes, host, start_port, num_successors)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Construtor.
</p>
<ul>
<li><p>
<tt>num_vnodes</tt> - Quantidade de Virtual Nodes dessa instancia do <a
href="Chord.html">Chord</a>.
</p>
</li>
<li><p>
<tt>host</tt> - Host que esta rodando.
</p>
</li>
<li><p>
<tt>start_port</tt> - Porta inicial.
</p>
</li>
<li><p>
<tt>num_successors</tt> - Número de sucessores.
</p>
</li>
</ul>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File chord.rb, line 17</span>
17:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">num_vnodes</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">start_port</span>, <span class="ruby-identifier">num_successors</span>)
18:       <span class="ruby-ivar">@num_vnodes</span> = <span class="ruby-identifier">num_vnodes</span>
19:       <span class="ruby-ivar">@start_port</span> = <span class="ruby-identifier">start_port</span>
20:       <span class="ruby-ivar">@num_successors</span> = <span class="ruby-identifier">num_successors</span>
21:       <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">host</span>
22:       <span class="ruby-ivar">@virtual_nodes</span> = []
23:       <span class="ruby-ivar">@all_successors</span> = []
24:       <span class="ruby-ivar">@succs_added_callback</span> = <span class="ruby-keyword kw">nil</span>
25:       <span class="ruby-ivar">@succs_leaved_callback</span> = <span class="ruby-keyword kw">nil</span>
26:       <span class="ruby-ivar">@lock</span> = <span class="ruby-constant">Mutex</span>.<span class="ruby-identifier">new</span>
27:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="create-method" class="method-detail ">
				<a name="method-i-create"></a>

				<div class="method-heading">
				
					<span class="method-name">create</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Inicia as operacoes do <a href="Chord.html">Chord</a>. Esse metodo
e&#8217; chamado para criar um novo <a href="Chord.html">Chord</a> ring.
Caso contrario o metodo <a href="Chord.html#method-i-join">Chord.join</a>
deve ser usado para ingressar em um <a href="Chord.html">Chord</a> ja
existente. Cria um Vnode que depois serve de base para o ingresso dos
outros Vnodes restantes.
</p>
					

					
					<div class="method-source-code"
						id="create-source">
<pre>
    <span class="ruby-comment cmt"># File chord.rb, line 34</span>
34:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>
35:       <span class="ruby-ivar">@virtual_nodes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">LocalVirtualNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Key</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@host}:#{@start_port}&quot;</span>),
36:                                                   <span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@start_port</span>, <span class="ruby-ivar">@num_successors</span>,
37:                                                   <span class="ruby-identifier">method</span>(<span class="ruby-value">:succ_updated</span>))
38:       <span class="ruby-ivar">@start_port</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
39:       
40:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">create</span>
41:       
42:       (<span class="ruby-ivar">@num_vnodes</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
43:         <span class="ruby-ivar">@virtual_nodes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">LocalVirtualNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Key</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@host}:#{@start_port}&quot;</span>),
44:                                                     <span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@start_port</span>, <span class="ruby-ivar">@num_successors</span>,
45:                                                     <span class="ruby-identifier">method</span>(<span class="ruby-value">:succ_updated</span>))
46:         <span class="ruby-ivar">@start_port</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
47:         <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">first</span>)
48:       <span class="ruby-keyword kw">end</span>
49:       
50:       <span class="ruby-ivar">@all_successors</span> = {}
51:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
52:         <span class="ruby-ivar">@all_successors</span>[<span class="ruby-identifier">node</span>.<span class="ruby-identifier">node_id</span>] = [] <span class="ruby-comment cmt">#node.get_succ_list</span>
53:       <span class="ruby-keyword kw">end</span>      
54:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="finish-method" class="method-detail ">
				<a name="method-i-finish"></a>

				<div class="method-heading">
				
					<span class="method-name">finish</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Finaliza as atividades dando um leave para cada virtual node.
</p>
					

					
					<div class="method-source-code"
						id="finish-source">
<pre>
    <span class="ruby-comment cmt"># File chord.rb, line 92</span>
92:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">finish</span>
93:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
94:         <span class="ruby-identifier">node</span>.<span class="ruby-identifier">leave</span>
95:       <span class="ruby-keyword kw">end</span>
96:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="join-method" class="method-detail ">
				<a name="method-i-join"></a>

				<div class="method-heading">
				
					<span class="method-name">join</span><span
						class="method-args">(host, port)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Ingressa em um <a href="Chord.html">Chord</a> ja existen atraves do host e
porta passados.
</p>
					

					
					<div class="method-source-code"
						id="join-source">
<pre>
    <span class="ruby-comment cmt"># File chord.rb, line 57</span>
57:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">join</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
58:       <span class="ruby-ivar">@virtual_nodes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">LocalVirtualNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Key</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@host}:#{@start_port}&quot;</span>),
59:                                                   <span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@start_port</span>, <span class="ruby-ivar">@num_successors</span>,
60:                                                   <span class="ruby-identifier">method</span>(<span class="ruby-value">:succ_updated</span>))
61:       <span class="ruby-ivar">@start_port</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
62:       
63:       <span class="ruby-keyword kw">begin</span>
64:         <span class="ruby-identifier">remote_node</span> = <span class="ruby-constant">RemoteVirtualNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'druby'</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
65:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
66:         <span class="ruby-identifier">raise</span>(<span class="ruby-constant">Exception</span>, <span class="ruby-value str">&quot;Join: Remote Node Dont Exist&quot;</span>)
67:       <span class="ruby-keyword kw">end</span>
68:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">remote_node</span>)
69:       
70:       (<span class="ruby-ivar">@num_vnodes</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
71:         <span class="ruby-ivar">@virtual_nodes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">LocalVirtualNode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Key</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;#{@host}:#{@start_port}&quot;</span>),
72:                                                     <span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@start_port</span>, <span class="ruby-ivar">@num_successors</span>,
73:                                                     <span class="ruby-identifier">method</span>(<span class="ruby-value">:succ_updated</span>))
74:         <span class="ruby-ivar">@start_port</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
75:         <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">first</span>)
76:       <span class="ruby-keyword kw">end</span>
77:       
78:       <span class="ruby-ivar">@all_successors</span> = {}
79:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
80:         <span class="ruby-ivar">@all_successors</span>[<span class="ruby-identifier">node</span>.<span class="ruby-identifier">node_id</span>] = [] <span class="ruby-comment cmt">#node.get_succ_list</span>
81:       <span class="ruby-keyword kw">end</span>
82:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="lookup-method" class="method-detail ">
				<a name="method-i-lookup"></a>

				<div class="method-heading">
				
					<span class="method-name">lookup</span><span
						class="method-args">(key)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Retorna o responsavel pela chave passada.
</p>
					

					
					<div class="method-source-code"
						id="lookup-source">
<pre>
    <span class="ruby-comment cmt"># File chord.rb, line 85</span>
85:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">key</span>)
86:       <span class="ruby-comment cmt">#TODO Otimizar para usar como ponto de partida o virtual node mais proximo da chave procurada </span>
87:       <span class="ruby-identifier">hash_key</span> = <span class="ruby-constant">Key</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>)
88:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">find_successor</span>(<span class="ruby-identifier">hash_key</span>)
89:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="print-nodes-method" class="method-detail ">
				<a name="method-i-print_nodes"></a>

				<div class="method-heading">
				
					<span class="method-name">print_nodes</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Imprime informacoes sobre cada virtual node dessse <a
href="Chord.html">Chord</a>.
</p>
					

					
					<div class="method-source-code"
						id="print-nodes-source">
<pre>
     <span class="ruby-comment cmt"># File chord.rb, line 99</span>
 99:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_nodes</span>
100:       <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
101:       <span class="ruby-ivar">@virtual_nodes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
102:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;----------------------------------------------------------------&quot;</span>
103:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">to_s</span>
104:         <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node ID: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">node_id</span>.<span class="ruby-identifier">to_s</span>
105:         <span class="ruby-keyword kw">begin</span>
106:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node Pred:&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">get_pred_list</span>.<span class="ruby-identifier">node_id</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">get_pred_list</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
107:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
108:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node Pred: NIL&quot;</span>
109:         <span class="ruby-keyword kw">end</span>
110:         <span class="ruby-keyword kw">begin</span>
111:           <span class="ruby-identifier">node</span>.<span class="ruby-identifier">get_succ_list</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">succ</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node Succ:&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">succ</span>.<span class="ruby-identifier">node_id</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">succ</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>}
112:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
113:           <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Node Succ: Inconsistente&quot;</span>
114:         <span class="ruby-keyword kw">end</span>
115:         <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
116:       <span class="ruby-keyword kw">end</span>  
117:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">'--------------------------------------------------------'</span>
118:       <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&quot;</span>
119:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="succs-added-method" class="method-detail ">
				<a name="method-i-succs_added"></a>

				<div class="method-heading">
				
					<span class="method-name">succs_added</span><span
						class="method-args">(&block)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Define o bloco que sera usado como callback quando novos no&#8217;s forem
adicionadas.
</p>
					

					
					<div class="method-source-code"
						id="succs-added-source">
<pre>
     <span class="ruby-comment cmt"># File chord.rb, line 122</span>
122:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succs_added</span>(&amp;<span class="ruby-identifier">block</span>)
123:       <span class="ruby-ivar">@succs_added_callback</span> = <span class="ruby-identifier">block</span>
124:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="succs-leaved-method" class="method-detail ">
				<a name="method-i-succs_leaved"></a>

				<div class="method-heading">
				
					<span class="method-name">succs_leaved</span><span
						class="method-args">(&block)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Define o bloco que sera usado como callback quando no&#8217;s sairem do <a
href="Chord.html">Chord</a>.
</p>
					

					
					<div class="method-source-code"
						id="succs-leaved-source">
<pre>
     <span class="ruby-comment cmt"># File chord.rb, line 127</span>
127:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succs_leaved</span>(&amp;<span class="ruby-identifier">block</span>)
128:       <span class="ruby-ivar">@succs_leaved_callback</span> = <span class="ruby-identifier">block</span>
129:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="private-instance-method-details" class="method-section section">
			<h3 class="section-header">Private Instance Methods</h3>

		
			<div id="succ-updated-method" class="method-detail ">
				<a name="method-i-succ_updated"></a>

				<div class="method-heading">
				
					<span class="method-name">succ_updated</span><span
						class="method-args">(id, successors)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Esse metodo e passado como callback para os Vnodes de tal forma que ao
ocorrem alteracoes na sua lista de sucessores ele e&#8217; chamado.
</p>
					

					
					<div class="method-source-code"
						id="succ-updated-source">
<pre>
     <span class="ruby-comment cmt"># File chord.rb, line 134</span>
134:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succ_updated</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">successors</span>)
135:       <span class="ruby-keyword kw">begin</span>
136:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">lock</span>
137:         
138:         <span class="ruby-ivar">@all_successors</span>.<span class="ruby-identifier">each_value</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">succ_list</span><span class="ruby-operator">|</span>
139:           <span class="ruby-identifier">succ_list</span>.<span class="ruby-identifier">delete_if</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">succ</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">succ</span>.<span class="ruby-identifier">ping</span>}
140:         <span class="ruby-keyword kw">end</span>
141:         
142:         <span class="ruby-identifier">all_succs_ids</span> = []
143:         <span class="ruby-identifier">all_succs</span> = <span class="ruby-ivar">@all_successors</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">flatten</span>
144:         <span class="ruby-identifier">all_succs</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">all_succs_ids</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">node_id</span>}
145:         
146:         <span class="ruby-identifier">new_succs</span> = []
147:         <span class="ruby-identifier">successors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">succ</span><span class="ruby-operator">|</span>
148:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">all_succs_ids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">succ</span>.<span class="ruby-identifier">node_id</span>)
149:             <span class="ruby-identifier">new_succs</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">succ</span>        
150:           <span class="ruby-keyword kw">end</span> 
151:         <span class="ruby-keyword kw">end</span>
152:         
153:         <span class="ruby-identifier">aux_succs</span> = <span class="ruby-ivar">@all_successors</span>[<span class="ruby-identifier">id</span>]
154:         
155:         <span class="ruby-identifier">all_succs_ids</span> = []
156:         <span class="ruby-ivar">@all_successors</span>[<span class="ruby-identifier">id</span>] = <span class="ruby-identifier">successors</span>
157:         <span class="ruby-identifier">all_succs</span> = <span class="ruby-ivar">@all_successors</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">flatten</span>
158:         <span class="ruby-identifier">all_succs</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">all_succs_ids</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">node_id</span>}
159:         
160:         <span class="ruby-identifier">leaved_succs</span> = []
161:         <span class="ruby-identifier">aux_succs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">succ</span><span class="ruby-operator">|</span>
162:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">all_succs_ids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">succ</span>.<span class="ruby-identifier">node_id</span>)
163:             <span class="ruby-identifier">leaved_succs</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">succ</span>
164:           <span class="ruby-keyword kw">end</span>
165:         <span class="ruby-keyword kw">end</span>
166:         
167:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_succs</span>
168:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@succs_added_callback</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
169:             <span class="ruby-identifier">new_succs</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@succs_added_callback</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">s</span>)}
170:           <span class="ruby-keyword kw">end</span>
171:         <span class="ruby-keyword kw">end</span>
172:         
173:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">leaved_succs</span>
174:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@succs_leaved_callback</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
175:             <span class="ruby-identifier">leaved_succs</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@succs_leaved_callback</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">s</span>)}
176:           <span class="ruby-keyword kw">end</span>
177:         <span class="ruby-keyword kw">end</span>
178:   
179:       <span class="ruby-keyword kw">ensure</span>
180:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">unlock</span>
181:       <span class="ruby-keyword kw">end</span>
182:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

